<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="https://cdn.jsdelivr.net/npm/vue"></script>
    <style>

    </style>
</head>

<body>
    <div id="app">
        <child></child>
    </div>
</body>

<template id="temp"> 
    <div>
       <h1>这是标题</h1>
       <p>{{num}}</p> 
       <button @click="add(10)">+1</button>
    </div>
</template>

<script>
    let child = {
        template: '#temp',
        data() { //注意一下data写法跟下面直接使用vue实例有点不一样！data是一个方法且返回一个对象，返回的对象里面的属性我们可以拿出来用
            return {
                num: 111
            }
        },
        methods: {
            add(val) {
                this.num += val
            }
        },
    }

    let vm = new Vue({
        el: '#app',
        data: {},
        components: {
            child
        }
    })
</script>

</html>